<?php
class Exts_Models_Acl {
	

	
    public function getResources( $path )
    {
        $handle = opendir(  $path );
        $filters = array(
            'ErrorController.php',
            'UserController.php',
            '.svn',
            'Action.php',
            'Action',
            'GenericSecureController.php',
            'SecureAction.php',
            'ServerAction.php',
            'User.php',
            'WSProxyServerAction.php',
			'Cron.php', 
        	'SecureRemoteAction.php'

        );
        $acl = array();
        if ( $handle ) {
            while (false !== ($file = readdir($handle))) {
                if ($file != "." && $file != "..") {
                    if( in_array( $file, $filters )) {
                        continue;
                    }
                    $class = ereg_replace( ".php", "", $file );
                    
                    $resource = ereg_replace( "Controller.php", "", $file );
                    if( $file != 'AclController.php') {
                        Zend_Loader::loadFile(  $path . $file );

                    }
                    $refletion = new ReflectionClass( $class );
                    $methods = $refletion->getMethods( ReflectionMethod::IS_PUBLIC );
                    if( ! count( $methods ) ) {
                        continue;
                    }
                    foreach( $methods as $m ) {
                        if( $m->class != $class ) {
                            continue;
                        }
                        
                        if( strpos( $m->name, 'Action' ) ) {
                            $acl[$resource][] = ereg_replace("Action","",$m->name);
                        }
                    }
                }
                
            }
            closedir($handle);
        }
        return $acl;    
    }

}